//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.custom.lockscreen;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class CLockScreenView extends View {
    private CLockScreenView.OnLockResultReturnListener onLockResultReturnListener;
    Paint linePaint = new Paint();
    Paint whiteLinePaint = new Paint();
    Paint textPaint = new Paint();
    Paint defaultPaint = new Paint();
    Paint selectPaint = new Paint();
    Paint movePaint = new Paint();
    boolean isMove = false;
    Bitmap defaultBitmap = null;
    int defaultBitmapDiameter = 32;
    int defaultBitmapRadius = 16;
    Bitmap selectedBitmap = null;
    int selectedBitmapDiameter = 120;
    int selectedBitmapRadius;
    CLockScreenView.PointInfo[] points;
    CLockScreenView.PointInfo startPoint;
    int width;
    int height;
    int moveX;
    int moveY;
    boolean isUp;
    StringBuffer lockString;
    private int startX;
    private int startY;

    public CLockScreenView(Context context) {
        super(context);
        this.selectedBitmapRadius = this.selectedBitmapDiameter / 2;
        this.points = new CLockScreenView.PointInfo[9];
        this.startPoint = null;
        this.isUp = false;
        this.lockString = new StringBuffer();
        this.startX = 0;
        this.startY = 0;
        this.setBackgroundColor(-1);
        this.initPaint();
    }

    public CLockScreenView(Context context, int resoId, int lockResoId) {
        super(context);
        this.selectedBitmapRadius = this.selectedBitmapDiameter / 2;
        this.points = new CLockScreenView.PointInfo[9];
        this.startPoint = null;
        this.isUp = false;
        this.lockString = new StringBuffer();
        this.startX = 0;
        this.startY = 0;
        this.setBackgroundColor(-1);
        this.defaultBitmap = BitmapFactory.decodeResource(this.getResources(), resoId);
        this.selectedBitmap = BitmapFactory.decodeResource(this.getResources(), lockResoId);
        this.defaultBitmapDiameter = this.defaultBitmap.getWidth();
        this.defaultBitmapRadius = this.defaultBitmap.getWidth() / 2;
        this.selectedBitmapDiameter = this.selectedBitmap.getWidth();
        this.selectedBitmapRadius = this.selectedBitmapDiameter / 2;
        this.initPaint();
    }

    public CLockScreenView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.selectedBitmapRadius = this.selectedBitmapDiameter / 2;
        this.points = new CLockScreenView.PointInfo[9];
        this.startPoint = null;
        this.isUp = false;
        this.lockString = new StringBuffer();
        this.startX = 0;
        this.startY = 0;
        this.setBackgroundColor(-1);
        this.initPaint();
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        this.width = this.getWidth();
        this.height = this.getHeight();
        if(this.width != 0 && this.height != 0) {
            this.initPoints(this.points);
        }

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }

    protected void onDraw(Canvas canvas) {
        if(this.moveX != 0 && this.moveY != 0 && this.startX != 0 && this.startY != 0) {
            this.drawLine(canvas, (float)this.startX, (float)this.startY, (float)this.moveX, (float)this.moveY);
        }

        this.drawNinePoint(canvas);
        super.onDraw(canvas);
    }

    public boolean onTouchEvent(MotionEvent event) {
        boolean flag = true;
        this.handlingEvent(event);
        return flag;
    }

    private void handlingEvent(MotionEvent event) {
        int downY;
        int len;
        switch(event.getAction()) {
            case 0:
                int downX = (int)event.getX();
                downY = (int)event.getY();
                CLockScreenView.PointInfo[] var11 = this.points;
                len = this.points.length;

                for(int var10 = 0; var10 < len; ++var10) {
                    CLockScreenView.PointInfo temp = var11[var10];
                    if(temp.isInMyPlace(downX, downY)) {
                        temp.setSelected(true);
                        this.startPoint = temp;
                        this.startX = temp.getCenterX();
                        this.startY = temp.getCenterY();
                        this.lockString.append(temp.getId());
                        break;
                    }
                }

                this.invalidate(0, 0, this.width, this.height);
                break;
            case 1:
                this.startX = this.startY = this.moveX = this.moveY = 0;
                this.isUp = true;
                if(this.onLockResultReturnListener != null) {
                    this.onLockResultReturnListener.onLockResult(this.lockString.toString());
                }

                this.finishDraw();
                this.invalidate();
                break;
            case 2:
                this.moveX = (int)event.getX();
                this.moveY = (int)event.getY();
                CLockScreenView.PointInfo[] var5 = this.points;
                int var4 = this.points.length;

                for(downY = 0; downY < var4; ++downY) {
                    CLockScreenView.PointInfo temp = var5[downY];
                    if(temp.isInMyPlace(this.moveX, this.moveY) && temp.isNotSelected()) {
                        temp.setSelected(true);
                        this.startX = temp.getCenterX();
                        this.startY = temp.getCenterY();
                        len = this.lockString.length();
                        if(len != 0) {
                            int preId = this.lockString.charAt(len - 1) - 48;
                            this.points[preId].setNextId(temp.getId());
                        }

                        this.lockString.append(temp.getId());
                        break;
                    }
                }

                this.invalidate(0, 0, this.width, this.height);
        }

    }

    private void finishDraw() {
        CLockScreenView.PointInfo[] var4 = this.points;
        int var3 = this.points.length;

        for(int var2 = 0; var2 < var3; ++var2) {
            CLockScreenView.PointInfo temp = var4[var2];
            temp.setSelected(false);
            temp.setNextId(temp.getId());
        }

        this.lockString.delete(0, this.lockString.length());
        this.isUp = false;
        this.invalidate();
    }

    private void initPoints(CLockScreenView.PointInfo[] points) {
        int len = points.length;
        int seletedSpacing = (this.width - this.selectedBitmapDiameter * 3) / 4;
        int seletedX = seletedSpacing;
        int seletedY = seletedSpacing;
        int defaultX = seletedSpacing + this.selectedBitmapRadius - this.defaultBitmapRadius;
        int defaultY = seletedSpacing + this.selectedBitmapRadius - this.defaultBitmapRadius;

        for(int i = 0; i < len; ++i) {
            if(i == 3 || i == 6) {
                seletedX = seletedSpacing;
                seletedY += this.selectedBitmapDiameter + seletedSpacing;
                defaultX = seletedSpacing + this.selectedBitmapRadius - this.defaultBitmapRadius;
                defaultY += this.selectedBitmapDiameter + seletedSpacing;
            }

            points[i] = new CLockScreenView.PointInfo(i, defaultX, defaultY, seletedX, seletedY);
            seletedX += this.selectedBitmapDiameter + seletedSpacing;
            defaultX += this.selectedBitmapDiameter + seletedSpacing;
        }

    }

    private void initPaint() {
        this.initLinePaint(this.linePaint);
        this.initTextPaint(this.textPaint);
        this.initWhiteLinePaint(this.whiteLinePaint);
        this.initDefaultPaint();
        this.initSelectPaint();
        this.initMovePaint();
    }

    private void initTextPaint(Paint paint) {
        this.textPaint.setTextSize(30.0F);
        this.textPaint.setAntiAlias(true);
        this.textPaint.setTypeface(Typeface.MONOSPACE);
    }

    private void initDefaultPaint() {
        this.defaultPaint.setAntiAlias(true);
        this.defaultPaint.setTypeface(Typeface.MONOSPACE);
    }

    private void initSelectPaint() {
        this.selectPaint.setColor(-65536);
        this.selectPaint.setAntiAlias(true);
        this.selectPaint.setTypeface(Typeface.MONOSPACE);
    }

    private void initMovePaint() {
        this.movePaint.setAntiAlias(true);
        this.movePaint.setColor(-16776961);
        this.movePaint.setStyle(Style.FILL);
        this.movePaint.setStrokeWidth(3.0F);
    }

    private void initLinePaint(Paint paint) {
        paint.setColor(-7829368);
        paint.setStrokeWidth((float)this.defaultBitmapDiameter);
        paint.setAntiAlias(true);
        paint.setStrokeCap(Cap.ROUND);
    }

    private void initWhiteLinePaint(Paint paint) {
        paint.setColor(-1);
        paint.setStrokeWidth((float)(this.defaultBitmapDiameter - 5));
        paint.setAntiAlias(true);
        paint.setStrokeCap(Cap.ROUND);
    }

    private void drawNinePoint(Canvas canvas) {
        if(this.startPoint != null) {
            this.drawEachLine(canvas, this.startPoint);
        }

        CLockScreenView.PointInfo[] var5 = this.points;
        int var4 = this.points.length;

        for(int var3 = 0; var3 < var4; ++var3) {
            CLockScreenView.PointInfo pointInfo = var5[var3];
            RectF rf;
            if(pointInfo.isSelected()) {
                if(this.selectedBitmap != null) {
                    if(this.isMove) {
                        Matrix matrix = new Matrix();
                        matrix.reset();
                        int i = (int)Math.abs(Math.random() * 1000.0D - 640.0D);
                        matrix.setRotate((float)i);
                        Bitmap temp = null;
                        temp = Bitmap.createBitmap(this.selectedBitmap, 0, 0, this.selectedBitmap.getWidth(), this.selectedBitmap.getHeight(), matrix, false);
                        canvas.drawBitmap(temp, (float)pointInfo.getSeletedX(), (float)pointInfo.getSeletedY(), (Paint)null);
                    } else {
                        canvas.drawBitmap(this.selectedBitmap, (float)pointInfo.getSeletedX(), (float)pointInfo.getSeletedY(), (Paint)null);
                    }
                } else {
                    rf = new RectF((float)pointInfo.getSeletedX(), (float)pointInfo.getSeletedY(), (float)(pointInfo.getSeletedX() + this.selectedBitmapDiameter), (float)(pointInfo.getSeletedY() + this.selectedBitmapDiameter));
                    if(this.isMove) {
                        RectF rfSmall = new RectF((float)pointInfo.getSeletedX(), (float)pointInfo.getSeletedY(), (float)(pointInfo.getSeletedX() + 10), (float)(pointInfo.getSeletedY() + 10));
                        int i = (int)Math.abs(Math.random() * 1000.0D - 640.0D);
                        if(i != 0) {
                            canvas.rotate((float)i, (float)(pointInfo.getSeletedX() + this.selectedBitmapDiameter / 2), (float)(pointInfo.getSeletedY() + this.selectedBitmapDiameter / 2));
                        }

                        canvas.drawOval(rf, this.selectPaint);
                        canvas.drawOval(rfSmall, this.movePaint);
                        if(i != 0) {
                            canvas.rotate((float)(-i), (float)(pointInfo.getSeletedX() + this.selectedBitmapDiameter / 2), (float)(pointInfo.getSeletedY() + this.selectedBitmapDiameter / 2));
                        }
                    } else {
                        canvas.drawOval(rf, this.selectPaint);
                    }
                }
            }

            if(this.defaultBitmap != null) {
                canvas.drawBitmap(this.defaultBitmap, (float)pointInfo.getDefaultX(), (float)pointInfo.getDefaultY(), (Paint)null);
            } else {
                rf = new RectF((float)pointInfo.getDefaultX(), (float)pointInfo.getDefaultY(), (float)(pointInfo.getDefaultX() + this.defaultBitmapDiameter), (float)(pointInfo.getDefaultY() + this.defaultBitmapDiameter));
                canvas.drawOval(rf, this.defaultPaint);
            }
        }

    }

    private void drawEachLine(Canvas canvas, CLockScreenView.PointInfo point) {
        if(point.hasNextId()) {
            int n = point.getNextId();
            this.drawLine(canvas, (float)point.getCenterX(), (float)point.getCenterY(), (float)this.points[n].getCenterX(), (float)this.points[n].getCenterY());
            this.drawEachLine(canvas, this.points[n]);
        }

    }

    private void drawLine(Canvas canvas, float startX, float startY, float stopX, float stopY) {
        canvas.drawLine(startX, startY, stopX, stopY, this.linePaint);
        canvas.drawLine(startX, startY, stopX, stopY, this.whiteLinePaint);
    }

    public void setOnLockResultReturnListener(CLockScreenView.OnLockResultReturnListener onLockResultReturnListener) {
        this.onLockResultReturnListener = onLockResultReturnListener;
    }

    public void setMove(boolean isMove) {
        this.isMove = isMove;
    }

    public interface OnLockResultReturnListener {
        void onLockResult(String var1);
    }

    private class PointInfo {
        private int id;
        private int nextId;
        private boolean selected;
        private int defaultX;
        private int defaultY;
        private int seletedX;
        private int seletedY;

        public PointInfo(int id, int defaultX, int defaultY, int seletedX, int seletedY) {
            this.id = id;
            this.nextId = id;
            this.defaultX = defaultX;
            this.defaultY = defaultY;
            this.seletedX = seletedX;
            this.seletedY = seletedY;
        }

        public boolean isSelected() {
            return this.selected;
        }

        public boolean isNotSelected() {
            return !this.isSelected();
        }

        public void setSelected(boolean selected) {
            this.selected = selected;
        }

        public int getId() {
            return this.id;
        }

        public int getDefaultX() {
            return this.defaultX;
        }

        public int getDefaultY() {
            return this.defaultY;
        }

        public int getSeletedX() {
            return this.seletedX;
        }

        public int getSeletedY() {
            return this.seletedY;
        }

        public int getCenterX() {
            return this.seletedX + CLockScreenView.this.selectedBitmapRadius;
        }

        public int getCenterY() {
            return this.seletedY + CLockScreenView.this.selectedBitmapRadius;
        }

        public boolean hasNextId() {
            return this.nextId != this.id;
        }

        public int getNextId() {
            return this.nextId;
        }

        public void setNextId(int nextId) {
            this.nextId = nextId;
        }

        public boolean isInMyPlace(int x, int y) {
            boolean inX = x > this.seletedX && x < this.seletedX + CLockScreenView.this.selectedBitmapDiameter;
            boolean inY = y > this.seletedY && y < this.seletedY + CLockScreenView.this.selectedBitmapDiameter;
            return inX && inY;
        }
    }
}
